<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/9/19
 * Time: 13:31
 */

namespace app\admin\controller;

use app\admin\model\RoomProfit as RoomProfitModel;
class RoomProfit extends Index
{
    //报备房间
    public function index()
    {
        return view();
    }
    //报备房间数据
    public function indexData()
    {
        $roomProfitModel = new RoomProfitModel();
        $data = $roomProfitModel->indexData();
        return json($data);
    }
    //报备房间添加
    public function roomProfitAdd()
    {
        $roomProfitModel = new RoomProfitModel();
        $res = $roomProfitModel->roomProfitAdd();
        return $res;
    }

    //切换状态
    public function changeStatus()
    {
        $roomProfitModel = new RoomProfitModel();
        $res = $roomProfitModel->changeStatus();
        return $res;
    }

    //代充记录
    public function RechargeRecord()
    {
        $roomProfitModel = new RoomProfitModel();
        $res = $roomProfitModel->RechargeRecord();
//        return $res;
//        halt($res);
        return view('recharge_record')->assign($res);
    }
    //房间权限控制
    public function powerControl()
    {
        $id = input('id');
        $roomProfitModel = new RoomProfitModel();
        $open = $roomProfitModel->where(['id'=>$id])->value('open');
        $open = unserialize($open);
        return view('power_control')->assign(['open'=>$open,'id'=>$id]);
    }
    //修改权限控制
    public function changePower()
    {
        $data = input('post.');
      //  halt($data);
        $new_open = [ 'exchange'=>$data['exchange'],'withdraw'=>$data['withdraw'],'recharge'=>$data['recharge'] ];
        $new_open = serialize($new_open);
        $roomProfitModel = new RoomProfitModel();
        $open = $roomProfitModel->where(['id'=>$data['id']])->value('open');
        if($new_open == $open) return ['code'=>-100,'msg'=>'保持原有设置'];

        $res = $roomProfitModel->save([ 'open'  =>$new_open ],['id' => $data['id']]);
        if($res) return ['code'=>100,'msg'=>'修改成功'];
        else return ['code'=>-100,'msg'=>'修改失败'];
    }

    //导出房间上周流水
    public function lastWeekFlow()
    {
        $roomProfitModel = new RoomProfitModel();
        $roomProfitModel->lastWeekFlow();
    }
}